Blitz Sonic Tutorial-2 : Adding animations
Sometimes you may want to add some extra animations or modify existing animations for the game ,this guide will show you how to do it,First thing you'll need is a copy of Blitz Sonic 's Source code and most recent version of Blitz3D (thanks to 06hypersonic60 for providing the code used) Falling animation * First thing to do is to set up the animation. You should first open the "Game_Resources_Models.bb" file to add the animation frames.What we need is RecursiveExtractAnimSeq(Mesh_Sonic, 0, 223) ; Idle RecursiveExtractAnimSeq(Mesh_Sonic, 225, 248) ; Walking RecursiveExtractAnimSeq(Mesh_Sonic, 250, 258) ; Running RecursiveExtractAnimSeq(Mesh_Sonic, 259, 266) ; Spinning Just duplicate the last line and change the numbers so they match the frames numbers on the model to get something like this ( just an example ) RecursiveExtractAnimSeq(Mesh_Sonic, 0, 223) ;Idle RecursiveExtractAnimSeq(Mesh_Sonic, 225, 248) ; Walking RecursiveExtractAnimSeq(Mesh_Sonic, 250, 258) ; Running RecursiveExtractAnimSeq(Mesh_Sonic, 259, 266) ; Spinning RecursiveExtractAnimSeq(Mesh_Sonic, 266, 285) ; Falling Step 2 * Now save and open the "player_Animation.bb" then find these Case ACTION_JUMP p\Animation\Animation = 3 Case ACTION_CROUCH p\Animation\Animation = 1 Case ACTION_SPINDASH p\Animation\Animation = 3 Then add Case ACTION_FALL p\Animation\Animation = 4 P.S: the number of the animation depends on what you have added before. So if you did add another animation before the fall one the number will be 5. Now find this If (p\Animation\Animation<>p\Animation\PreviousAnimation) Then Select p\Animation\Animation Case 0 RecursiveAnimate(p\Objects\Mesh, 1, 0.2, 1, 8) Case 1 RecursiveAnimate(p\Objects\Mesh, 1, 0.4, 2, 8) p\Animation\Time# = 0.0 Case 2 RecursiveAnimate(p\Objects\Mesh, 1, 0.4, 3, 9) p\Animation\Time# = 0.0 Case 3 RecursiveAnimate(p\Objects\Mesh, 1, 0.4, 4, 8) And add a case 4 like the others. And as U can see, there's a number that always change: Case 0 >>1Case 1 >> and so on. Each time you add a case you add 1 to that number.'''And the number that cames before it, ( 0.2 / 0.4 ) can be used to change the animation's speed. Now the animation is added. You only need to code the action to make it play in game '''Step 3 * Now go to the "player_managements.bb" That's where the Actions are all coded.First we should add a new action named fall ( it will be empty since it's just an animation that we want to play ) ; = ; Player_Action_Fall ; = Function Player_Action_Fall(p.tPlayer, d.tDeltaTime) ; Land If (p\Motion\Ground = True) Then p\Action = ACTION_COMMON End Function Then go up to the action common and add If ((Not p\Action = ACTION_JUMP) And (p\Motion\Ground= False)) p\Action = ACTION_FALL End If Step 4 * And finally open "player.bb" to add the action fall in the list of the available actions Find : ; Action constants and add Const ACTION_FALL= 4 P.S: '''Const ACTION_FALL= 4 cause we didn't add another action before' and finally go down 'til u find this Case ACTION_SPINDASH Player_Action_Spindash(p, d) End Select And add just after it the following code : Case ACTION_FALL Player_Action_Fall(p, d) Skidding animation * First thing to do is to set up the animation. You should first open the "Game_Resources_Models.bb" file to add the animation frames.What we need is RecursiveExtractAnimSeq(Mesh_Sonic, 0, 223) ; Idle RecursiveExtractAnimSeq(Mesh_Sonic, 225, 248) ; Walking RecursiveExtractAnimSeq(Mesh_Sonic, 250, 258) ; Running RecursiveExtractAnimSeq(Mesh_Sonic, 259, 266) ; Spinning Just duplicate the last line and change the numbers so they match the frames numbers on the model to get something like this ( just an example ) RecursiveExtractAnimSeq(Mesh_Sonic, 0, 223) ;Idle RecursiveExtractAnimSeq(Mesh_Sonic, 225, 248) ; Walking RecursiveExtractAnimSeq(Mesh_Sonic, 250, 258) ; Running RecursiveExtractAnimSeq(Mesh_Sonic, 259, 266) ; Spinning RecursiveExtractAnimSeq(Mesh_Sonic, 266, 285) ; Falling '''Step 2' * Now save and open the "player_Animation.bb" then find these Case ACTION_JUMP p\Animation\Animation = 3 Case ACTION_CROUCH p\Animation\Animation = 1 Case ACTION_SPINDASH p\Animation\Animation = 3 Then add Case ACTION_SKID p\Animation\Animation = 4 P.S: the number of the animation depends on what you have added before. So ' if you did add another animation before the fall one the number will be 5. Now find this If (p\Animation\Animation<>p\Animation\PreviousAnimation) Then Select p\Animation\Animation Case 0 RecursiveAnimate(p\Objects\Mesh, 1, 0.2, 1, 8) Case 1 RecursiveAnimate(p\Objects\Mesh, 1, 0.4, 2, 8) p\Animation\Time# = 0.0 Case 2 RecursiveAnimate(p\Objects\Mesh, 1, 0.4, 3, 9) p\Animation\Time# = 0.0 Case 3 RecursiveAnimate(p\Objects\Mesh, 1, 0.4, 4, 8) And add a case 4 like the others. And as you can see, there's a number that always change: Case 0 >>1Case 1 >> and so on. '''Each time you add a case you add 1 to that number.'And the number that cames before it, ( 0.2 / 0.4 ) can be used to change the animation's speed. Now the animation is added. You only need to code the action to make it play in game Now in player_managements.bb go find this: If (Speed_Length#>0.4) Then p\Flags\Skidding = True If (ChannelPlaying(Channel_Skidding)=False) Then Channel_Skidding = PlaySound(Sound_Skidding) End If and add this line between: "If (Speed_Length#>0.4) Then" and "End If" p\Action = ACTION_SKID Then duplicate the ACTION_COMMON ( all of it ) and change this line : Function Player_Action_Common(p.tPlayer, d.tDeltaTime) With Function Player_Action_Skid(p.tPlayer, d.tDeltaTime) Then add after that line the following code Skid= Skid+(game\deltaTime\timeCurrentFrame-Game\DeltaTime\TimePreviousFrame) If Skid > 500 Then p\Action = ACTION_COMMON : Skid = 0 Now you only need to go to up and add : Global Skid = 0 '''P.S be sure that line isn't in a function or it won't work And finally do the same things that you did for action fall in the player.bb to make it work External Links * Blitz Sonic coding tutorials at OBSG Forums Category:Guides